 /** \file logicparser.h
 * \brief Header file for a simple logic proposition parser.
 * \author Marcelo Lira dos Santos
 * \date 2006-2007
 *
 * This is free software; you can redistribute it and/or modify it under the
 * terms of the GNU General Public License, see the file LICENSE.
 */
#ifndef __LOGIC_PARSER_H
#define __LOGIC_PARSER_H
#include <glib.h>

// Constants
// Reserved characters
#define C_LPAR		'('
#define C_RPAR		')'
#define C_AND		'&'
#define C_OR		'|'
#define C_IF		'-'
#define C_IF1		'>'
#define C_NOT		'!'
#define C_FALSE	'F'
#define C_TRUE		'T'
#define C_ID		'P'
#define C_ILLEGAL	'X'

#define NO_ID		-1
#define BASE_LEVEL	0

// Macros
#define LPNODE_TO_GPOINTER(n)	((gpointer)	(n))
#define GPOINTER_TO_LPNODE(p)	((LpNode *)	(p))
#define LPTOKEN_TO_GPOINTER(t)	((gpointer)	(t))
#define GPOINTER_TO_LPTOKEN(p)	((LpToken *)	(p))
#define IS_TERMINAL(t)	(t == C_ID || t == C_TRUE || t == C_FALSE)

// Data Types
typedef struct _LpToken
{
	gint nodeType;	// tipo do token (C_IF, C_ID, etc)
	gint nodeId;	// ID do token (caso seja do tipo C_ID)
	gint level;		// nivel do token dentro da expressao
} LpToken;

typedef struct _LpNode
{
	LpToken *lpToken;
	gint node_id;
	struct _LpNode *left;
	struct _LpNode *right;
} LpNode;

// Functions
GList *lp_dissect (gchar *expr);
LpNode *lp_parse (GList *tokLst);
LpNode *lp_parse_expression (gchar *expr);
gchar *lp_get_node_text (LpToken *token);

#endif // __LOGIC_PARSER_H
